/* 
 * File:   RequestHandler.h
 * Author: faraj
 *
 * Created on October 4, 2009, 8:41 PM
 */

#ifndef _REQUESTHANDLER_H
#define	_REQUESTHANDLER_H
#include "COMMANDS.h"
#include "../CTools/CTools.h"
#include "Responser.h"

static bool handleRequest(Client* cli)
{
    vector<string> args;
    
    string *val = cli->getText();
    
    if(val == NULL)
    {
        return false;
    }
    
    Tokenize(*val,args);
    
    string command = args[0];
   
    cout << *(cli->getAddress()->getAddress()) << " : " <<*val << endl;
    
    if(command.find(COMMAND_HELP)==0)
    {   
        cout << "COMMAND_HELP" << endl;
        response_help(cli, &args);
    }
    else if(command.find(COMMAND_VERSION)==0)
    {
        cout << "COMMAND_VERSION" << endl;
        response_version(cli, &args);
    }
    else if(command.find(COMMAND_QUIT)==0)
    {
        cout << "COMMAND_QUIT" << endl;
        response_quit(cli, &args);
    }
    else if(command.find(COMMAND_GET_FILE)==0)
    {
        cout << "COMMAND_GET_FILE" << endl;
       response_get(cli, &args);
    }
    else if(command.find(COMMAND_PUT_FILE)==0)
    {
        cout << "COMMAND_PUT_FILE" << endl;
        response_put(cli, &args);
    }
    else if(command.find(COMMAND_DEL)==0)
    {
        cout << "COMMAND_DEL_FILE" << endl;
        response_del(cli, &args);
    }
    else
    {
        cli->sendText("\nunknown command");
    }
    return true;
}


#endif	/* _REQUESTHANDLER_H */

